package com.ztx.controller;

import com.ztx.annotation.AuthToken;
import com.ztx.pojo.Menu;
import com.ztx.service.MenuService;
import com.ztx.service.PermissionService;
import com.ztx.utils.CommonResult;
import com.ztx.utils.JwtTokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@AuthToken
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    HttpServletRequest request;

    @Autowired
    JwtTokenUtil jwtTokenUtil;

    @Autowired
    MenuService menuService;

    @GetMapping
    public CommonResult<List<Menu>> getMenu(){

        String token = request.getHeader("Authorization").substring(7);

        Long userId = jwtTokenUtil.getUserIdFromToken(token);
        List<Menu> menus = menuService.getMenu(userId);

        return CommonResult.success(menus);
    }
}
